# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from polymorphic import PolymorphicModel
from settings import STATIC_ROOT, VERSION
import os, sys, datetime
# Create your models here.


class Category(models.Model):
	title = models.CharField(max_length=50, verbose_name=u'Title')
	icon = models.FilePathField(path=STATIC_ROOT+'/png/', blank=True, verbose_name=u'Icon')
	color = models.CharField(max_length=7,blank=True, verbose_name=u'Color')
	public		= models.BooleanField(default=False, verbose_name=u'Public')
	user		= models.ForeignKey(User, null=True, blank=True, verbose_name=u'User')
	def __unicode__(self):
		return self.title
	def geticon(self):
		return '<img src="/static/png/%s" class="caticon" title="%s">' % (os.path.basename(self.icon),self.title)

class Entity(PolymorphicModel):
	title		= models.CharField(max_length=500, blank=False, verbose_name=u'Title')
	content		= models.TextField(blank=True, null=True, verbose_name=u'Content')
	user		= models.ForeignKey(User, null=False, blank=False, verbose_name=u'User')
	exist		= models.BooleanField(default=True, verbose_name=u'Exist')
	datetime		= models.DateTimeField(default=datetime.datetime.now(), verbose_name=u'Time')
	del_datetime		= models.DateTimeField(auto_now=False, null=True, blank=True, verbose_name=u'Delete Time')
	#status			= models.IntegerField(null=False, default=0, max_length=1, verbose_name=u'Status')
	#type			= models.IntegerField(null=False, default=0, max_length=1, verbose_name=u'Type')
	links_users		= models.ManyToManyField(User, verbose_name=u'Linked users', null=True,blank=True, related_name='UserLinks')
	#links_entity		= models.ManyToManyField(Entity, verbose_name=u'Linked entities', null=True)
	category		= models.ForeignKey(Category,null=True,blank=True, verbose_name=u'Category')
	def __unicode__(self):
		return self.title

class Note(Entity):
	def __unicode__(self):
		return self.title

class Secure(Entity):
	def __unicode__(self):
		return self.title+':'+self.content

class	SimpleTodo(Entity):
	done		= models.BooleanField(default=False, verbose_name=u'Done')
	done_datetime		= models.DateTimeField(auto_now=False, null=True,blank=True, verbose_name=u'Done Time')
	till_date		= models.DateField(auto_now=False, null=True,blank=True, verbose_name=u'Till date')
	priority			= models.IntegerField(null=False, default=0, max_length=1, verbose_name=u'Priority')
	#status			= models.IntegerField(null=False, default=0, max_length=1, verbose_name=u'Status')
	def __unicode__(self):
		return self.title

class	Link(Entity):
	alias		= models.CharField(max_length=100, blank=True, null=True, verbose_name=u'Alias')
	def __unicode__(self):
		return self.title
